# $Id$
# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Alexey D. <lq07829icatm at rambler.ru>

pkgbase=plasma-workspace
pkgname=(plasma-workspace kuiserver plasma-wayland-session)
pkgver=5.10.95
pkgrel=3
pkgdesc='KDE Plasma Workspace'
arch=(i686 x86_64)
url='https://www.kde.org/workspaces/plasmadesktop/'
license=(LGPL)
# note on libxdamage:
# not detected by namcap because libgl depends on it
# but nvidia providing libgl does not depend on libxdamage
depends=(kjsembed knotifyconfig libxdamage libksysguard ktexteditor libqalculate qt5-tools kde-cli-tools
         xorg-xrdb xorg-xsetroot kactivitymanagerd kholidays xorg-xmessage xorg-xprop milou prison kwin
         plasma-integration kdelibs4support)
makedepends=(extra-cmake-modules kdoctools gpsd baloo appstream-qt krunner networkmanager-qt kdesignerplugin)
groups=(plasma)
source=("https://download.kde.org/unstable/plasma/$pkgver/$pkgbase-$pkgver.tar.xz"{,.sig} kde.pam
        plasma-workspace-qqc2-style.patch::"https://cgit.kde.org/plasma-workspace.git/patch/?id=6bbb0c79")
sha256sums=('f651d454564c880a8edb2bae1c034410df5e27e02f349b081cf666ea494e7131'
            'SKIP'
            '00090291204baabe9d6857d3b1419832376dd2e279087d718b64792691e86739'
            '8c416dde6a185e26519f3c32592056e9e96eb3a1dece8f23f15d5732d5158cba')
validpgpkeys=('2D1D5B0588357787DE9EE225EC94D18F7F05997E'  # Jonathan Riddell
              '348C8651206633FD983A8FC4DEACEA00075E1D76'  # KDE Neon
              'D07BD8662C56CB291B316EB2F5675605C74E02CF') # David Edmundson

prepare() {
  mkdir -p build

  cd $pkgname-$pkgver
  patch -p1 -i ../plasma-workspace-qqc2-style.patch # don't set QQC2 desktop style globally
}

build() {
  cd build
  cmake ../$pkgbase-$pkgver \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DCMAKE_INSTALL_LIBEXECDIR=lib \
    -DBUILD_TESTING=OFF
  make
}

package_plasma-workspace() {
  depends+=(kuiserver)
  optdepends=('plasma-workspace-wallpapers: additional wallpapers'
              'gpsd: GPS based geolocation' 'networkmanager-qt: IP based geolocation'
              'kdepim-addons: displaying PIM events in the calendar'
              'appmenu-qt4: global menu support for Qt4 applications'
              'qt5-virtualkeyboard: virtual keyboard support in lock screen'
              'baloo: Baloo search runner'
              'appstream-qt: package search runner')
  provides=(notification-daemon)

  cd build
  make DESTDIR="$pkgdir" install

  install -Dm644 "$srcdir"/kde.pam "$pkgdir"/etc/pam.d/kde

  # Remove conflicts with kuiserver
  rm "$pkgdir"/usr/bin/kuiserver5
  rm "$pkgdir"/usr/lib/libkdeinit5_kuiserver5.so
  rm "$pkgdir"/usr/share/dbus-1/services/kf5_org.kde.kuiserver.service
  rm "$pkgdir"/usr/share/kservices5/kuiserver.desktop
  rm "$pkgdir"/etc/xdg/kuiserver.categories

  # Split plasma-wayland scripts
  rm -r "$pkgdir"/usr/share/wayland-sessions
}

package_kuiserver() {
  pkgdesc='KDE Progress Info UI server'
  depends=(kxmlgui)

  cd build/kuiserver
  make DESTDIR="$pkgdir" install
}

package_plasma-wayland-session() {
  pkgdesc='Plasma Wayland session'
  depends=(plasma-workspace qt5-wayland kwayland-integration xorg-server-xwayland)
  groups=()

  install -Dm644 build/plasmawayland.desktop "$pkgdir"/usr/share/wayland-sessions/plasmawayland.desktop
}
